package com.bobo;

import java.awt.*;

/**
 * @Author: bobobo
 * @Date: 2019/9/5 19:53
 * @Version：1.0
 */
public class MonteCarloExperiment {
    private int squareSide;
    private int N;
    private int outputInterval;

    public MonteCarloExperiment(int squareSide,int N){
        if (squareSide < 0 || N < 0)
            throw new IllegalArgumentException("squareSide and N must larger than 0");

        this.squareSide = squareSide;
        this.N = N;
    }


    public void setOutputInterval(int outputInterval) {
        if (outputInterval < 0)
            throw new IllegalArgumentException("outputInterval must larger than 0");
        this.outputInterval = outputInterval;
    }

    public void run(){
        Circle circle = new Circle(squareSide / 2, squareSide / 2, squareSide / 2);
        MonteCarloPIData piData = new MonteCarloPIData(circle);

        for (int i = 0;i < N;i++){
            if (i % outputInterval == 0)
                System.out.println(piData.getPI());

            int x = (int) (Math.random() * squareSide);
            int y = (int) (Math.random() * squareSide);
            piData.addPoint(new Point(x,y));
        }
    }


    public static void main(String[] args) {
        int squareSide = 800;
        int N = 10000000;

        MonteCarloExperiment experiment = new MonteCarloExperiment(squareSide, N);
        experiment.setOutputInterval(10000);
        experiment.run();
    }
}
